/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogCadSaidaCheque.java
 *
 * Created on 16/11/2011, 17:39:00
 */
package camada.apresentacao.dialog.cheques;

import camada.bancodedados.daoimplemente.cheques.ChequeDAOImpl;
import eloma.classe.SaidaCheques;
import java.util.List;
import javax.swing.ListSelectionModel;
import tabelamodelcolumnmodel.cheque.SaidaChequeColumnModel;
import tabelamodelcolumnmodel.cheque.SaidaChequeTableModel;
import utilitarios.Exceptions;

/**
 *
 * @author icaro
 */
public class DialogCadSaidaCheque extends javax.swing.JDialog {

    Exceptions exceptions = new Exceptions();
    ChequeDAOImpl daoSaidaCheque = new ChequeDAOImpl();
    int indexTabela;

    /**
     * Creates new form DialogCadSaidaCheque
     */
    public DialogCadSaidaCheque(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        setTitle("Liberar Cheques");
        carregarTabela(null);
    }

    //<editor-fold desc="Metod para cerregar tabela">
    private void sum() {
        try {
            float soma = 0;
            for (int i = 0; i < tabelaSaidaCheque.getRowCount(); i++) {
                Float valor = (Float) tabelaSaidaCheque.getValueAt(i, 2);
                soma += valor.doubleValue();
            }
            labelSomaTabela.setText(String.valueOf(soma));

        } catch (Exception e) {
        }
    }
//</editor-fold>

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        rbTodos = new javax.swing.JRadioButton();
        rbFiltros = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        rbLiberados = new javax.swing.JRadioButton();
        rbPendentes = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        cpMes = new com.toedter.calendar.JMonthChooser();
        jLabel2 = new javax.swing.JLabel();
        cpAno = new com.toedter.calendar.JYearChooser();
        rbNumeroCheque = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        txtNumeroCheque = new javax.swing.JFormattedTextField();
        rbData = new javax.swing.JRadioButton();
        btPesquisa = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaSaidaCheque = new javax.swing.JTable();
        btVoltar = new javax.swing.JButton();
        btCancelarLiberacao = new javax.swing.JButton();
        btLiberar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        labelSomaTabela = new javax.swing.JLabel();
        labelSomaTabela1 = new javax.swing.JLabel();

        jButton2.setText("jButton2");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtros"));

        jRadioButton1.setText("jRadioButton1");

        buttonGroup1.add(rbTodos);
        rbTodos.setSelected(true);
        rbTodos.setText("Todos");
        rbTodos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbTodosActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbFiltros);
        rbFiltros.setText("Escolher Filtros");
        rbFiltros.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbFiltrosActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        buttonGroup2.add(rbLiberados);
        rbLiberados.setText("Liberados");
        rbLiberados.setEnabled(false);
        rbLiberados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbLiberadosActionPerformed(evt);
            }
        });

        buttonGroup2.add(rbPendentes);
        rbPendentes.setText("Pendentes");
        rbPendentes.setEnabled(false);
        rbPendentes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPendentesActionPerformed(evt);
            }
        });

        jLabel1.setText("Mês:");

        cpMes.setEnabled(false);

        jLabel2.setText("Ano:");

        cpAno.setEnabled(false);

        buttonGroup2.add(rbNumeroCheque);
        rbNumeroCheque.setText("Por Número do Cheque");
        rbNumeroCheque.setEnabled(false);
        rbNumeroCheque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbNumeroChequeActionPerformed(evt);
            }
        });

        jLabel3.setText("Número Cheque:");

        txtNumeroCheque.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        txtNumeroCheque.setEnabled(false);

        buttonGroup2.add(rbData);
        rbData.setText("Por Data");
        rbData.setToolTipText("");
        rbData.setEnabled(false);
        rbData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbDataActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rbLiberados)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbPendentes)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(cpMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cpAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(79, 79, 79)
                                .addComponent(jLabel2)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNumeroCheque, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addContainerGap(107, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(rbData)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
                        .addComponent(rbNumeroCheque)
                        .addGap(68, 68, 68))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbLiberados)
                    .addComponent(rbPendentes)
                    .addComponent(rbData)
                    .addComponent(rbNumeroCheque))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cpMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cpAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNumeroCheque, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btPesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ima/outros/Pesquisa.png"))); // NOI18N
        btPesquisa.setText("Pesquisar");
        btPesquisa.setEnabled(false);
        btPesquisa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPesquisaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(rbTodos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbFiltros))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(435, Short.MAX_VALUE)
                        .addComponent(btPesquisa)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbTodos)
                    .addComponent(rbFiltros))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btPesquisa)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tabelaSaidaCheque.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tabelaSaidaCheque.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaSaidaChequeMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                tabelaSaidaChequeMouseEntered(evt);
            }
        });
        jScrollPane1.setViewportView(tabelaSaidaCheque);

        btVoltar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ima/cadastro/Voltar.png"))); // NOI18N
        btVoltar.setText("Voltar");
        btVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btVoltarActionPerformed(evt);
            }
        });

        btCancelarLiberacao.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ima/saidacheque/Cancelar_Baixa.png"))); // NOI18N
        btCancelarLiberacao.setText("Cancelar Liberação");
        btCancelarLiberacao.setEnabled(false);
        btCancelarLiberacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarLiberacaoActionPerformed(evt);
            }
        });

        btLiberar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ima/saidacheque/Baixa.png"))); // NOI18N
        btLiberar.setText("Liberar Cheque");
        btLiberar.setEnabled(false);
        btLiberar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLiberarActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Arial Black", 0, 12)); // NOI18N
        jLabel4.setText("Valor Total Cheques:");

        labelSomaTabela.setFont(new java.awt.Font("Arial Black", 0, 12)); // NOI18N
        labelSomaTabela.setText("jLabel5");

        labelSomaTabela1.setFont(new java.awt.Font("Arial Black", 0, 12)); // NOI18N
        labelSomaTabela1.setText("R$");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btVoltar)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelSomaTabela1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelSomaTabela, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btLiberar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btCancelarLiberacao)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancelarLiberacao)
                    .addComponent(btLiberar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(labelSomaTabela)
                    .addComponent(labelSomaTabela1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(btVoltar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void rbFiltrosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbFiltrosActionPerformed

        btPesquisa.setEnabled(true);

        rbLiberados.setEnabled(true);
        rbPendentes.setEnabled(true);
        rbNumeroCheque.setEnabled(true);
        rbData.setEnabled(true);

    }//GEN-LAST:event_rbFiltrosActionPerformed

    private void rbTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbTodosActionPerformed

        rbLiberados.setEnabled(false);
        rbPendentes.setEnabled(false);
        rbNumeroCheque.setEnabled(false);
        rbData.setEnabled(false);

        cpAno.setEnabled(false);
        cpMes.setEnabled(false);

        txtNumeroCheque.setEnabled(false);

        btPesquisa.setEnabled(false);

        carregarTabela(null);

    }//GEN-LAST:event_rbTodosActionPerformed

        private void btVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVoltarActionPerformed
    }//GEN-LAST:event_btVoltarActionPerformed

    private void rbNumeroChequeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbNumeroChequeActionPerformed
        rbLiberados.setEnabled(true);
        rbPendentes.setEnabled(true);
        rbNumeroCheque.setEnabled(true);

        cpAno.setEnabled(false);
        cpMes.setEnabled(false);

        txtNumeroCheque.setEnabled(true);
    }//GEN-LAST:event_rbNumeroChequeActionPerformed

    private void rbPendentesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPendentesActionPerformed
        cpAno.setEnabled(false);
        cpMes.setEnabled(false);
        txtNumeroCheque.setEnabled(false);
    }//GEN-LAST:event_rbPendentesActionPerformed

    private void rbLiberadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbLiberadosActionPerformed
        cpAno.setEnabled(false);
        cpMes.setEnabled(false);
        txtNumeroCheque.setEnabled(false);
    }//GEN-LAST:event_rbLiberadosActionPerformed

    private void btLiberarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLiberarActionPerformed
        try {

            indexTabela = tabelaSaidaCheque.getSelectedRow();

            SaidaChequeTableModel modelTabela = (SaidaChequeTableModel) tabelaSaidaCheque.getModel();

            SaidaCheques saidaCheque = modelTabela.getValoresSaidaCheque(indexTabela);

            daoSaidaCheque.atualizarSituacaoCheque(saidaCheque.getIdCheque(), "Liberado");

            btLiberar.setEnabled(false);
            btCancelarLiberacao.setEnabled(false);

            carregarTabela(null);

        } catch (Exception ex) {
        }
    }//GEN-LAST:event_btLiberarActionPerformed

    private void tabelaSaidaChequeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaSaidaChequeMouseClicked

        try {

            indexTabela = tabelaSaidaCheque.getSelectedRow();

            SaidaChequeTableModel modelTabela = (SaidaChequeTableModel) tabelaSaidaCheque.getModel();

            SaidaCheques saidaCheque = modelTabela.getValoresSaidaCheque(indexTabela);

            if ("Pendente".equals(saidaCheque.getSituacao())) {
                btLiberar.setEnabled(true);
                btCancelarLiberacao.setEnabled(false);
            } else if ("Liberado".equals(saidaCheque.getSituacao())) {
                btLiberar.setEnabled(false);
                btCancelarLiberacao.setEnabled(true);
            }
        } catch (Exception ex) {
        }

    }//GEN-LAST:event_tabelaSaidaChequeMouseClicked

    private void btCancelarLiberacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarLiberacaoActionPerformed
        try {

            indexTabela = tabelaSaidaCheque.getSelectedRow();

            SaidaChequeTableModel modelTabela = (SaidaChequeTableModel) tabelaSaidaCheque.getModel();

            SaidaCheques saidaCheque = modelTabela.getValoresSaidaCheque(indexTabela);

            daoSaidaCheque.atualizarSituacaoCheque(saidaCheque.getIdCheque(), "Pendente");

            btLiberar.setEnabled(false);
            btCancelarLiberacao.setEnabled(false);

            carregarTabela(null);

        } catch (Exception ex) {
        }
    }//GEN-LAST:event_btCancelarLiberacaoActionPerformed

    private void tabelaSaidaChequeMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaSaidaChequeMouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_tabelaSaidaChequeMouseEntered

    private void rbDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbDataActionPerformed
        cpAno.setEnabled(true);
        cpMes.setEnabled(true);
        txtNumeroCheque.setEnabled(false);
    }//GEN-LAST:event_rbDataActionPerformed

    private void btPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPesquisaActionPerformed
        try {

            List<SaidaCheques> listaCheques;

            if (rbLiberados.isSelected() == true) {

                listaCheques = daoSaidaCheque.selecionarChequeLiberadosDoMes();

                carregarTabela(listaCheques);

            } else if (rbPendentes.isSelected() == true) {

                listaCheques = daoSaidaCheque.selecionarChequePendentesDoMes();

                carregarTabela(listaCheques);

            } else if (rbData.isSelected() == true) {

                int ano = cpAno.getYear();
                int mes = cpMes.getMonth() + 1;

                listaCheques = daoSaidaCheque.selecionarChequePorData(ano, mes);

                carregarTabela(listaCheques);

            } else if (rbNumeroCheque.isSelected() == true) {

                if (txtNumeroCheque.getText() != "") {

                    listaCheques = daoSaidaCheque.selecionarChequePorNumeroCheque(Integer.parseInt(txtNumeroCheque.getText()));

                    carregarTabela(listaCheques);

                } else {

                }

            }

        } catch (Exception ex) {

        }
    }//GEN-LAST:event_btPesquisaActionPerformed

    private void carregarTabela(List<SaidaCheques> lista) {
        try {

            List<SaidaCheques> listaSaidaCheques;

            if (lista != null) {
                listaSaidaCheques = lista;
            } else {
                listaSaidaCheques = daoSaidaCheque.selecionarChequeDoMes();
            }

            tabelaSaidaCheque.setModel(new SaidaChequeTableModel(listaSaidaCheques));

            tabelaSaidaCheque.setAutoCreateColumnsFromModel(false);
            java.awt.FontMetrics fm = tabelaSaidaCheque.getFontMetrics(tabelaSaidaCheque.getFont());

            tabelaSaidaCheque.setColumnModel(new SaidaChequeColumnModel(fm));
            tabelaSaidaCheque.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

            sum();

        } catch (Exception ex) {
            exceptions.Exceptions(ex.getMessage().toString(), "DialogCadSaidaCheque - carregarTabela");
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DialogCadSaidaCheque.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DialogCadSaidaCheque.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DialogCadSaidaCheque.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DialogCadSaidaCheque.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                DialogCadSaidaCheque dialog = new DialogCadSaidaCheque(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelarLiberacao;
    private javax.swing.JButton btLiberar;
    private javax.swing.JButton btPesquisa;
    private javax.swing.JButton btVoltar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private com.toedter.calendar.JYearChooser cpAno;
    private com.toedter.calendar.JMonthChooser cpMes;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelSomaTabela;
    private javax.swing.JLabel labelSomaTabela1;
    private javax.swing.JRadioButton rbData;
    private javax.swing.JRadioButton rbFiltros;
    private javax.swing.JRadioButton rbLiberados;
    private javax.swing.JRadioButton rbNumeroCheque;
    private javax.swing.JRadioButton rbPendentes;
    private javax.swing.JRadioButton rbTodos;
    private javax.swing.JTable tabelaSaidaCheque;
    private javax.swing.JFormattedTextField txtNumeroCheque;
    // End of variables declaration//GEN-END:variables
}
